package cn.wxq.daily.empdailymgforserve.service.impl;

import cn.wxq.daily.empdailymgforserve.domain.Messages;
import cn.wxq.daily.empdailymgforserve.mapper.MessagesDao;
import cn.wxq.daily.empdailymgforserve.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessagesDao messagesDao;

    /**
     * 查询所有消息，主要用于PC端列表数据
     * @return
     */
    @Override
    public List<Messages> findAllMessages() {
        return messagesDao.findAllMessages();
    }

    /**
     * 根据消息类型或者标题查询数据
     * @param noticeType
     * @param noticeTitle
     * @return
     */
    @Override
    public List<Messages> findSomeMessages(String noticeType, String noticeTitle) {
        //多个参数，封装到map中，键值对应xml中的字段
//        System.out.println("消息类型："+ noticeType +"标题："+ noticeTitle);
        Map<String,String> paramMap=new HashMap<>();
        paramMap.put("noticeType",noticeType);
        paramMap.put("noticeTitle",noticeTitle);
        List<Messages> someMessages = messagesDao.findSomeMessages(paramMap);
        return someMessages;

    }

    @Override
    public int insertMessage(Messages messages) {
//        SimpleDateFormat temp=new SimpleDateFormat("yyyy-MM-dd HH:mm");  //这是24时
//        String courentdate=temp.format(date);

        messages.setCreateTime(new Date());
        System.out.println(messages.getCreateTime());
        int row = messagesDao.insertMessage(messages);
        return row;
    }

    @Override
    public int updateMessage(Messages messages) {
        return messagesDao.updateMessage(messages);
    }

    @Override
    public int deleteMessageById(Integer mesId) {
        return messagesDao.deleteMessageById(mesId);
    }

    @Override
    public Messages selectMessageById(Integer mesId) {
        return messagesDao.selectMessageById(mesId);
    }
}
